package com.example.java1query.infrastructure;

import com.example.java1query.domain.Hero;
import com.example.java1query.domain.dto.HeroDto;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface JpaHero extends JpaRepository<Hero,Long> , JpaSpecificationExecutor<Hero> {

    Hero findByHeroCode(String code);

    //业务建模 帮派等级在5级以上 和 成员 金钱数大于14000

    @Query("select h from Hero h" +
            " left join h.community c" +
            " where c.level > ?1" +
            " and h.basicInfo.money > ?2")
    List<Hero> queryMoneyAndLevel(Integer level, Integer money);

    @Query("select new com.example.java1query.domain.dto.HeroDto(h.heroCode,h.profession,c.communityCode,c.level,c.name)" +
            " from Hero h" +
            " left join h.community c" +
            " where c.level > ?1" +
            " and h.basicInfo.money > ?2")
    List<HeroDto> queryMoneyAndLevelDto(Integer level, Integer money);

}
